package cn.com.homeyoda.aimate.aihealth.ui.health.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.SportPlanTitleBean;

public class SportPlanTitleAdapter extends BaseQuickAdapter<SportPlanTitleBean.DataBean, BaseViewHolder> {

    public int getSelectPosition() {
        return selectPosition;
    }

    private int selectPosition = 0;

    public SportPlanTitleAdapter(int layoutResId, @Nullable List<SportPlanTitleBean.DataBean> data, Context context) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SportPlanTitleBean.DataBean item) {
        helper.setText(R.id.tv_title, item.getTypeName());

        if (selectPosition == helper.getAdapterPosition()) {
            helper.setTextColor(R.id.tv_title, mContext.getResources().getColor(R.color.colorPrimary));
            TextView tvTitle = helper.getView(R.id.tv_title);
            tvTitle.setTypeface(null, Typeface.BOLD);
            helper.setVisible(R.id.iv_select, true);
        } else {
            helper.setTextColor(R.id.tv_title, mContext.getResources().getColor(R.color.black_80));
            helper.setVisible(R.id.iv_select, false);
            TextView tvTitle = helper.getView(R.id.tv_title);
            tvTitle.setTypeface(null, Typeface.NORMAL);
        }
    }

    public void setSelectPosition(int position){
        selectPosition = position;
        notifyDataSetChanged();
    }

}
